{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>334</th>\n",
       "      <th>335</th>\n",
       "      <th>336</th>\n",
       "      <th>337</th>\n",
       "      <th>338</th>\n",
       "      <th>339</th>\n",
       "      <th>340</th>\n",
       "      <th>341</th>\n",
       "      <th>342</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.227483</td>\n",
       "      <td>-0.202770</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>0.700717</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>1.053769</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>208500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.670403</td>\n",
       "      <td>-0.086107</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>0.700717</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>-0.694099</td>\n",
       "      <td>1.858393</td>\n",
       "      <td>0.159469</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>181500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.316067</td>\n",
       "      <td>0.081281</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>0.987524</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>223500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.079843</td>\n",
       "      <td>-0.091179</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>-1.860986</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.788515</td>\n",
       "      <td>0.386636</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>0.954402</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>250000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 344 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6  \\\n",
       "0  0.227483 -0.202770  0.064327 -0.243378  0.700717  0.026216  0.226042   \n",
       "1  0.670403 -0.086107  0.064327 -0.243378  0.700717  0.026216  0.226042   \n",
       "2  0.316067  0.081281  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "3  0.079843 -0.091179  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "4  0.788515  0.386636  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "\n",
       "          7         8         9    ...      334  335  336  337  338  339  340  \\\n",
       "0  1.253123 -0.419233  1.053769    ...        1    1    1    1    1    1    1   \n",
       "1 -0.694099  1.858393  0.159469    ...        1    1    1    1    1    1    1   \n",
       "2  1.253123 -0.419233  0.987524    ...        1    1    1    1    1    1    1   \n",
       "3  1.253123 -0.419233 -1.860986    ...        1    1    1    1    1    1    1   \n",
       "4  1.253123 -0.419233  0.954402    ...        1    1    1    1    1    1    1   \n",
       "\n",
       "   341  342  SalePrice  \n",
       "0    1    1     208500  \n",
       "1    1    1     181500  \n",
       "2    1    1     223500  \n",
       "3    1    1     140000  \n",
       "4    1    1     250000  \n",
       "\n",
       "[5 rows x 344 columns]"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# path to where the data lies\n",
    "\n",
    "dpath = './week1_job_data/Ames_House/'\n",
    "train_data = pd.read_csv(dpath +\"AmesHouse_FE_train.csv\")\n",
    "test_data = pd.read_csv(dpath +\"AmesHouse_FE_test.csv\")\n",
    "#通过观察前5行，了解数据每列（特征）的概况\n",
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1456, 344)"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#样本数目、特征维数 每个特征的类型、空值样本的数目、数据类型\n",
    "train_data.shape\n",
    "\n",
    "# train_data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>...</th>\n",
       "      <th>333</th>\n",
       "      <th>334</th>\n",
       "      <th>335</th>\n",
       "      <th>336</th>\n",
       "      <th>337</th>\n",
       "      <th>338</th>\n",
       "      <th>339</th>\n",
       "      <th>340</th>\n",
       "      <th>341</th>\n",
       "      <th>342</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461</td>\n",
       "      <td>0.670403</td>\n",
       "      <td>0.119019</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>0.700717</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>-0.694099</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1462</td>\n",
       "      <td>0.699931</td>\n",
       "      <td>0.387346</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>-0.694099</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1463</td>\n",
       "      <td>0.493235</td>\n",
       "      <td>0.343014</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>-0.694099</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1464</td>\n",
       "      <td>0.611347</td>\n",
       "      <td>-0.047760</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>-0.694099</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1465</td>\n",
       "      <td>-0.422133</td>\n",
       "      <td>-0.552255</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 344 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Id         0         1         2         3         4         5         6  \\\n",
       "0  1461  0.670403  0.119019  0.064327 -0.243378  0.700717  0.026216  0.226042   \n",
       "1  1462  0.699931  0.387346  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "2  1463  0.493235  0.343014  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "3  1464  0.611347 -0.047760  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "4  1465 -0.422133 -0.552255  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "\n",
       "          7         8 ...   333  334  335  336  337  338  339  340  341  342  \n",
       "0 -0.694099 -0.419233 ...     1    1    1    1    1    1    1    1    1    1  \n",
       "1 -0.694099 -0.419233 ...     1    1    1    1    1    1    1    1    1    1  \n",
       "2 -0.694099 -0.419233 ...     1    1    1    1    1    1    1    1    1    1  \n",
       "3 -0.694099 -0.419233 ...     1    1    1    1    1    1    1    1    1    1  \n",
       "4  1.253123 -0.419233 ...     1    1    1    1    1    1    1    1    1    1  \n",
       "\n",
       "[5 rows x 344 columns]"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#2.3 数据探索  对数据的探索有助于我们在第三步中根据数据的特点选择合适的模型类型\n",
    "# 2.4 数据准备\n",
    "\n",
    "# 从原始数据中分离输入特征x和输出y\n",
    "y = train_data['SalePrice'].values\n",
    "X = train_data.drop('SalePrice', axis = 1)\n",
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.cross_validation import train_test_split\n",
    "\n",
    "# 随机采样25%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=20, test_size=0.2)\n",
    "\n",
    "# 当数据量比较大时，可用train_test_split从训练集中分出一部分做校验集；\n",
    "# 样本数目较少时，建议用交叉验证\n",
    "# 在线性回归中，留一交叉验证有简便计算方式，无需显式交叉验证\n",
    "\n",
    "# 下面将训练数据分割成训练集和测试集，只是让大家对模型的训练误差、校验集上的测试误差估计、和测试集上的测试误差做个比较，实际任务中无需这么处理。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test_data = test_data.drop('Id',axis = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.5 数据预处理／特征工程\n",
    "\n",
    "特征工程是实际任务中特别重要的环节。\n",
    "\n",
    "scikit learn中提供的数据预处理功能：\n",
    "http://scikit-learn.org/stable/modules/preprocessing.html\n",
    "http://scikit-learn.org/stable/modules/classes.html#module- sklearn.feature_extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#发现各特征差异较大，需要进行数据标准化预处理\n",
    "#标准化的目的在于避免原始特征值差异过大，导致训练得到的参数权重不归一，无法比较各特征的重要性\n",
    "\n",
    "# 数据标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "# 分别初始化对特征和目标值的标准化器\n",
    "ss_X = StandardScaler()\n",
    "ss_y = StandardScaler()\n",
    "\n",
    "# 分别对训练和测试数据的特征以及目标值进行标准化处理\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test = ss_X.transform(X_test)\n",
    "\n",
    "#y_train = ss_y.fit_transform(y_train)\n",
    "#y_test = ss_y.transform(y_test)\n",
    "\n",
    "y_train = ss_y.fit_transform(y_train.reshape(-1, 1))\n",
    "y_test = ss_y.transform(y_test.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型\n",
    "\n",
    "### 3.1 尝试缺省参数的线性回归\n",
    "\n",
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测，下面计算score会自动调用predict\n",
    "lr_y_predict = lr.predict(X_test)\n",
    "lr_y_predict_train = lr.predict(X_train)\n",
    "\n",
    "# 预测，下面计算score会自动调用predict\n",
    "lr_y_predict = lr.predict(X_test)\n",
    "predict_value_lr = lr.predict(test_data)\n",
    "\n",
    "#显示特征的回归系数\n",
    "print 'lr1.intercept_',lr.intercept_\n",
    "print 'lr1.coef_',lr.coef_\n",
    "lr.coef_\n",
    "\n",
    "#### 3.1.1 模型评价\n",
    "\n",
    "# 使用LinearRegression模型自带的评估模块（r2_score），并输出评估结果\n",
    "\n",
    "#测试集\n",
    "print 'The value of default measurement of LinearRegression on test is', lr.score(X_test, y_test)\n",
    "\n",
    "#训练集\n",
    "print 'The value of default measurement of LinearRegression on train is', lr.score(X_train, y_train)\n",
    "\n",
    "\n",
    "# predict_value_lr = lr.predict(test_data)\n",
    "# final_predict_value_lasso = np.exp(predict_value_lasso)\n",
    "final_predict_value_lr = ss_y.inverse_transform(predict_value_lr)\n",
    "# ss['sale_price'] = predict_value_lasso\n",
    "# ss.head()\n",
    "# pred_lasso = pd.DataFrame(predict_value_lasso, index=test_data[\"Id\"], columns=[\"SalePrice\"])\n",
    "pred_lr = pd.DataFrame(final_predict_value_lr, columns=[\"SalePrice\"])\n",
    "pred_lr.to_csv('Lr_Predicting_house_price_output.csv', header=True, index_label='Id')\n",
    "\n",
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - lr_y_predict_train,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');\n",
    "\n",
    "残差分布和高斯分布比较匹配，但还是左skew，可能是由于数据集中有16个数据的y值为最大值，有噪声（预测残差超过2.5）\n",
    "\n",
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, lr_y_predict_train)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RidgeCV(alphas=[0.01, 0.1, 1, 10, 20, 40, 80, 100, 200, 300, 320, 330, 360, 370, 375, 376, 377, 378, 379, 380, 390, 395, 400, 500, 1000, 10000],\n",
       "    cv=None, fit_intercept=True, gcv_mode=None, normalize=False,\n",
       "    scoring=None, store_cv_values=True)"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "alphas = [0.01, 0.1, 1, 10,20, 40, 80,100,200,300,320,330,360,370,375,376,377,378,379,380,390,395,400,500,1000,10000]\n",
    "reg = RidgeCV(alphas=alphas, store_cv_values=True)   \n",
    "reg.fit(X_train, y_train)       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xt4VdWd//H3N/dAgCQQEAgBxICi\n3OSAt4rY8YJ1irajVmdsrbXDtE+dX2esbbX2GX9jx5mOttr2V9vRadVebFWsVqp10CqIdrwQ5C4C\nkWu4JUjCLZDr9/fH3sHTGMgJh83JCZ/X85wn56y99jprK/DJWmtfzN0RERE5Whmp7oCIiKQ3BYmI\niCRFQSIiIklRkIiISFIUJCIikhQFiYiIJEVBIiIiSVGQiIhIUhQkIiKSlKxUd+B4GDBggI8YMSLV\n3RARSSuLFi3a6e4lndU7IYJkxIgRVFRUpLobIiJpxcw2JlJPU1siIpIUBYmIiCRFQSIiIklRkIiI\nSFIUJCIikpRIg8TMZpjZajOrNLPbOtj+JTNbbmZLzOx1Mxsbt+32cL/VZnZpom2KiMjxFVmQmFkm\n8ABwGTAWuC4+KEK/cfdx7j4RuAe4L9x3LHAtcDowA/iJmWUm2KaIiBxHUY5IpgKV7r7O3RuBx4Er\n4iu4+564j72Btuf+XgE87u4N7r4eqAzb67RNETlBvHBb8JKUi/KCxKHA5rjPVcBZ7SuZ2VeAW4Ac\n4ONx+77Zbt+h4ftO2wzbnQXMAigrK+t670Wke9u+PNU9kFCUIxLroMw/UuD+gLuPAr4JfLuTfRNq\nM2z3IXePuXuspKTTK/xFROQoRTkiqQKGxX0uBbYeof7jwE8T2LcrbYqISMSiHJEsBMrNbKSZ5RAs\nns+Jr2Bm5XEfLwfWhu/nANeaWa6ZjQT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bIolZAHwmfPBRCTANeBt4HfibcK1kEDA9bp9VwCnh+77AfmB3WO+yw3xPBtC2xvK3\nYftH0g/YFo6IPgtkxm0bTXreAl3SjEYkIol5hmD9YynBKOEb7r7dzH4H/BXBP9hrCJ4MuDvc53mC\nYPmTuy81s8XASmAd8OfDfM9+4HQzWxS285lO+vUT4HdmdjUwL9y/zYVhH0Qipbv/iiTJzArcfZ+Z\n9ScYpZwXhkw+wT/u54VrK4m0tc/dC45RvxYAV7h77bFoT+RwNCIRSd5z4QORcoDvuPt2AHc/YGZ3\nEjxXftPx7FA4/XafQkSOB41IREQkKVpsFxGRpChIREQkKQoSERFJioJERESSoiAREZGkKEhERCQp\n/x+4QBfaQXhLrQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xfb49860>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 377.0)\n",
      "('reg.intercept_:', array([ -1.54558534e-18]))\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[  1.76293129e-02,   2.99406095e-02,   1.91592109e-02,\n",
       "         -3.92183592e-03,  -6.09191497e-03,   0.00000000e+00,\n",
       "         -3.30889606e-03,   1.20824308e-02,   2.84579069e-02,\n",
       "          3.46510209e-02,   2.50582610e-02,   4.73874725e-02,\n",
       "          8.91864113e-03,  -8.29723122e-03,   5.82002606e-03,\n",
       "          2.27744996e-03,   4.82520771e-02,   6.85783164e-03,\n",
       "          4.87849250e-02,   4.19894490e-03,  -1.12888589e-02,\n",
       "         -2.99022272e-02,   1.49548430e-02,   8.82631723e-03,\n",
       "          8.91638485e-03,   1.30546965e-02,   4.37349247e-03,\n",
       "          1.84798538e-02,  -2.29777165e-04,  -1.20260189e-03,\n",
       "          1.59345513e-03,   2.13698222e-02,  -3.61931373e-02,\n",
       "         -3.09330794e-02,   1.44815960e-02,   2.46069866e-02,\n",
       "          4.76897009e-02,   1.48812110e-02,   6.19895014e-03,\n",
       "          9.69448297e-03,   5.04746436e-03,   6.30892098e-03,\n",
       "          1.12687996e-02,  -3.36930550e-03,   7.53510664e-03,\n",
       "          2.40148309e-02,   1.69322345e-02,  -9.04840905e-03,\n",
       "          6.29540409e-03,   2.11511983e-02,   5.66082740e-03,\n",
       "         -2.15825910e-03,   3.79200224e-03,   8.24435521e-03,\n",
       "          3.64838472e-02,   7.85814104e-03,   9.68888103e-03,\n",
       "          2.14412364e-03,   1.48812110e-02,   1.61111556e-02,\n",
       "          9.10415967e-03,   7.73946044e-03,   2.01656112e-02,\n",
       "          1.81981363e-02,   1.87568660e-02,   2.01892165e-03,\n",
       "          1.59625044e-02,   3.95256101e-02,   5.98979532e-02,\n",
       "          1.20334423e-02,   3.24179467e-02,   4.54208271e-02,\n",
       "          1.15490057e-02,   3.24485850e-02,   4.53963539e-02,\n",
       "          1.19481892e-02,   1.35617463e-02,   1.43925549e-02,\n",
       "          1.09558399e-02,   2.03122809e-02,   3.00689058e-02,\n",
       "         -1.94353985e-03,   3.09795714e-02,   3.99611785e-02,\n",
       "          1.21691242e-03,   1.76877044e-02,   1.57075586e-02,\n",
       "         -1.43143467e-03,   1.68950074e-02,   2.34813953e-02,\n",
       "          2.94968905e-03,   8.91864113e-03,   8.91864113e-03,\n",
       "          8.91864113e-03,   1.40899264e-02,   1.87888332e-02,\n",
       "          6.96358190e-03,   1.75962660e-02,  -3.77059289e-03,\n",
       "         -6.84484864e-03,  -9.39671714e-03,  -1.16975419e-02,\n",
       "          0.00000000e+00,  -9.74532920e-03,   9.74532920e-03,\n",
       "          0.00000000e+00,  -8.22790030e-03,  -1.77070772e-02,\n",
       "          1.92828655e-02,  -2.91344544e-03,  -4.11956402e-03,\n",
       "         -1.20047224e-02,   1.65205622e-03,  -2.01507248e-03,\n",
       "          7.04532968e-03,   0.00000000e+00,  -3.81115392e-03,\n",
       "         -2.91646978e-03,   4.49175289e-04,   1.20858860e-02,\n",
       "         -3.99054637e-03,   0.00000000e+00,   1.04906620e-03,\n",
       "          8.52182218e-04,   0.00000000e+00,   2.76058827e-03,\n",
       "          2.87471905e-04,   4.43545211e-03,   0.00000000e+00,\n",
       "         -3.55069090e-03,   2.15380110e-03,   3.48262890e-03,\n",
       "          1.24584695e-03,  -8.65032179e-04,   2.30605529e-02,\n",
       "         -2.11967470e-03,   9.44032144e-03,  -1.03089562e-02,\n",
       "          1.05002650e-03,   5.52082791e-03,  -4.92018724e-03,\n",
       "         -7.47976098e-04,   4.71486395e-03,   2.25125485e-03,\n",
       "         -1.46335679e-02,   1.93193391e-03,   0.00000000e+00,\n",
       "         -4.35546000e-03,   3.90369096e-04,  -2.09260675e-04,\n",
       "         -2.45654367e-03,  -2.11967470e-03,   1.31068798e-02,\n",
       "         -8.59565872e-03,   7.22384487e-04,   4.78202240e-03,\n",
       "          0.00000000e+00,  -1.12101868e-02,  -4.65240213e-03,\n",
       "         -4.42646245e-03,   5.84014125e-03,   4.66834906e-03,\n",
       "         -3.90868984e-03,   0.00000000e+00,  -3.75312570e-03,\n",
       "          6.79681859e-04,   2.15998774e-03,  -4.90801727e-03,\n",
       "          9.14497131e-04,   0.00000000e+00,  -9.26733562e-03,\n",
       "         -1.34692979e-02,   1.84489374e-02,   8.21926952e-03,\n",
       "         -3.93595841e-03,  -1.03430218e-02,   0.00000000e+00,\n",
       "          1.77929513e-02,   1.71727906e-03,  -1.36772251e-02,\n",
       "         -3.47821665e-03,   0.00000000e+00,  -2.19262142e-02,\n",
       "          1.72267877e-03,  -2.10040141e-03,   1.24862052e-02,\n",
       "         -6.88867379e-04,  -5.35890901e-03,   1.71727906e-03,\n",
       "          0.00000000e+00,   1.69783303e-03,   2.97151009e-03,\n",
       "         -5.83540231e-03,   1.30912213e-04,  -8.54211515e-03,\n",
       "          6.63253792e-03,   0.00000000e+00,  -4.84020641e-04,\n",
       "          5.28504802e-03,  -1.71439850e-03,  -1.38693546e-02,\n",
       "         -5.69342465e-04,   3.67416919e-03,  -5.79377488e-03,\n",
       "          4.55932092e-03,   0.00000000e+00,   2.29275230e-03,\n",
       "          2.12167151e-02,  -1.19015172e-02,  -8.28714905e-03,\n",
       "          0.00000000e+00,  -6.64425363e-03,   2.38263312e-02,\n",
       "         -8.13372855e-03,  -4.36248343e-03,  -3.78129758e-03,\n",
       "          0.00000000e+00,  -6.64011120e-03,   0.00000000e+00,\n",
       "         -1.67574872e-02,  -4.38570838e-03,  -6.98229472e-03,\n",
       "          8.44650790e-03,  -9.72403035e-03,   1.59424507e-03,\n",
       "         -2.75249974e-03,   4.07027530e-03,   1.15736787e-02,\n",
       "          1.04539326e-02,  -1.22642316e-02,  -3.66896263e-03,\n",
       "         -2.59851206e-03,  -6.84484864e-03,   0.00000000e+00,\n",
       "         -2.37600702e-02,   1.37897583e-02,   3.16942867e-03,\n",
       "          1.03649537e-02,  -1.45495740e-02,   0.00000000e+00,\n",
       "         -1.37826885e-02,  -9.20981292e-03,  -2.01892165e-03,\n",
       "          2.31601896e-02,   0.00000000e+00,   7.15411534e-04,\n",
       "          3.01301440e-03,  -7.02486024e-04,   5.20016467e-05,\n",
       "         -1.92863726e-02,   0.00000000e+00,   4.80449143e-03,\n",
       "         -1.53273366e-03,  -4.10440504e-03,  -1.26345421e-02,\n",
       "          9.80881801e-03,   9.12176384e-03,  -5.86031307e-03,\n",
       "         -1.72795286e-03,   6.17112929e-03,  -2.67554407e-03,\n",
       "         -5.67917166e-03,  -2.08281985e-03,   0.00000000e+00,\n",
       "         -1.29620209e-02,   4.06807907e-04,   5.52425407e-03,\n",
       "          1.17608304e-02,   1.62398324e-03,  -1.61813875e-02,\n",
       "          2.88356893e-02,  -2.07159162e-02,  -1.33999267e-02,\n",
       "         -3.84024739e-03,  -2.22614190e-02,  -1.38718958e-02,\n",
       "         -2.22574652e-02,   1.24345386e-02,  -8.29928076e-03,\n",
       "          1.77179165e-02,   6.99659250e-02,  -1.56389438e-02,\n",
       "         -8.20982787e-03,  -3.68743746e-03,  -4.07920836e-03,\n",
       "          8.90255592e-03,   4.31533263e-02,  -3.74442896e-03,\n",
       "          1.35195761e-02,   0.00000000e+00,  -4.82643710e-03,\n",
       "          1.11794855e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         -1.19364664e-02,  -1.29626548e-02,   3.72062884e-02,\n",
       "          0.00000000e+00,  -1.45512111e-03,  -1.42648759e-02,\n",
       "          2.21713308e-03,   1.42325996e-02,  -1.79661248e-03,\n",
       "          1.02656926e-02,   0.00000000e+00,  -1.95641222e-02,\n",
       "          4.57034839e-03,  -2.74464010e-03,  -3.82914563e-03,\n",
       "          1.73672605e-03,   1.59625044e-02,   0.00000000e+00,\n",
       "         -1.32740130e-02,   7.46874346e-03,   0.00000000e+00,\n",
       "          4.52027748e-03,  -3.71270015e-03,  -2.12831209e-03,\n",
       "          2.31263763e-02,   0.00000000e+00,  -1.39896143e-02,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "          0.00000000e+00]])"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(reg.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "plt.plot(np.log10(reg.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', reg.alpha_)\n",
    "print ('reg.intercept_:',reg.intercept_)\n",
    "reg.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of RidgeRegression is 0.90068353582\n"
     ]
    }
   ],
   "source": [
    "# 使用LinearRegression模型自带的评估模块（r2_score），并输出评估结果\n",
    "print 'The value of default measurement of RidgeRegression is', reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "predict_value_ridge = reg.predict(test_data)\n",
    "# final_predict_value_lasso = np.exp(predict_value_lasso)\n",
    "final_predict_value_ridge = ss_y.inverse_transform(predict_value_ridge)\n",
    "# ss['sale_price'] = predict_value_lasso\n",
    "# ss.head()\n",
    "# pred_lasso = pd.DataFrame(predict_value_lasso, index=test_data[\"Id\"], columns=[\"SalePrice\"])\n",
    "pred_ridge = pd.DataFrame(final_predict_value_ridge, columns=[\"SalePrice\"])\n",
    "pred_ridge.to_csv('Ridge_Predicting_house_price_output.csv', header=True, index_label='Id')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LassoCV(alphas=[0.0001, 0.001, 0.005, 0.008, 0.0082, 0.0083, 0.0089, 0.00895, 0.009, 0.0099, 0.01, 0.011, 0.012, 0.013, 0.015, 0.017, 0.05, 0.06, 0.1, 1, 10, 100],\n",
       "    copy_X=True, cv=None, eps=0.001, fit_intercept=True, max_iter=1000,\n",
       "    n_alphas=100, n_jobs=1, normalize=False, positive=False,\n",
       "    precompute='auto', random_state=None, selection='cyclic', tol=0.0001,\n",
       "    verbose=False)"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "alphas = [0.0001,0.001,0.005,0.008,0.0082,0.0083,0.0089,0.00895,0.009,0.0099,0.01,0.011,0.012,0.013,0.015,0.017,0.05,0.06, 0.1, 1, 10,100]\n",
    "\n",
    "lasso = LassoCV(alphas=alphas)   \n",
    "lasso.fit(X_train, y_train)       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHWxJREFUeJzt3Xt0nPV95/H3VzfLuvgmyeDYAvlO\nnBgwFVcbm2xCF9I90NDcSNNuk2z4Y8tusk22JUuX7Cane3bDNjmnG9KWZrOcbtOwtLmxCVtCUjpj\nsJ1gMBgb0Ei+38CPZFnWxbrOd/+Y0TDIsj2S9eiZy+d1jrGemd/MfB88o888z+/3/H7m7oiIiACU\nRV2AiIjkD4WCiIhkKBRERCRDoSAiIhkKBRERyVAoiIhIhkJBREQyFAoiIpKhUBARkYyKqAuYqsbG\nRm9paYm6DBGRgvLiiy92unvTxdoVXCi0tLSwc+fOqMsQESkoZnYol3Y6fSQiIhkKBRERyVAoiIhI\nhkJBREQyFAoiIpIRWiiY2XfM7KSZ7TnP/WZmf2ZmHWa228yuC6sWERHJTZhHCo8Bd1zg/juB1ek/\n9wF/HmItIiKSg9CuU3D3uJm1XKDJ3cBfe2o90B1mtsDMlrj7ibBqEpGLO9D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AKgCvjq+Ip+7nzWzL5Naw/jwbBaUPsX1dQWCzAYdKYiI\nSIY6mkVEJEOhICIiGQoFERHJUCiIiEiGQkFERDIUCiIikvH/ARWQUKEwJoV8AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xf092a58>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 0.0089499999999999996)\n",
      "('lasso.intercept_:', 7.64296459325256e-18)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([  1.20833225e-02,   2.90498990e-02,   9.70130960e-03,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         1.04188481e-01,   3.10955603e-02,   4.32978048e-02,\n",
       "         4.83649687e-04,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   4.94700613e-02,   0.00000000e+00,\n",
       "         9.18982295e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   3.08876428e-03,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   2.31257683e-02,  -3.78755651e-02,\n",
       "        -3.31766679e-02,   1.50874267e-02,   4.49021343e-02,\n",
       "         5.29629598e-02,   1.16957079e-02,   1.83864758e-03,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         2.36397576e-02,   1.12409018e-02,  -0.00000000e+00,\n",
       "         0.00000000e+00,   1.77135534e-02,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   1.49423662e-03,\n",
       "         9.85243623e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   2.09538593e-02,   4.69726470e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   1.90086578e-02,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   2.86150090e-01,\n",
       "         0.00000000e+00,   2.25624723e-02,   4.99088379e-02,\n",
       "         2.23600117e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         5.58987867e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   5.41948533e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   2.31437331e-03,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   3.53451121e-02,\n",
       "         0.00000000e+00,   3.04006094e-02,   6.10431904e-18,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   5.20978960e-02,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -4.72504022e-03,   4.42563130e-17,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -6.11934127e-03,\n",
       "         2.49803515e-02,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -5.83783861e-03,   0.00000000e+00,  -0.00000000e+00,\n",
       "         3.61155388e-04,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   6.76516343e-03,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   2.79545442e-02,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -1.50086023e-02,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -3.89730554e-03,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   9.17528107e-03,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -2.73061538e-03,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   2.82975159e-02,   4.58757361e-04,\n",
       "         0.00000000e+00,  -4.32317569e-03,   0.00000000e+00,\n",
       "         2.33499444e-02,  -0.00000000e+00,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -1.81014053e-02,\n",
       "         0.00000000e+00,  -0.00000000e+00,   3.30915312e-03,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -2.78422080e-03,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -7.84956798e-03,\n",
       "        -0.00000000e+00,   0.00000000e+00,  -6.36346549e-03,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         2.61311638e-02,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   2.44751201e-02,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -7.82855396e-03,  -0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -3.04615331e-03,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         1.59271601e-03,  -7.69713500e-03,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   0.00000000e+00,\n",
       "        -2.67793448e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,  -1.70762728e-02,   0.00000000e+00,\n",
       "        -7.38020886e-03,  -0.00000000e+00,   0.00000000e+00,\n",
       "         2.36384187e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "        -1.57718262e-02,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,  -5.01843652e-03,\n",
       "         5.14420812e-03,   4.95320329e-03,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   1.96274428e-03,  -0.00000000e+00,\n",
       "        -0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -1.10926664e-04,   0.00000000e+00,   0.00000000e+00,\n",
       "         1.78050903e-02,   0.00000000e+00,  -0.00000000e+00,\n",
       "         4.48677532e-02,  -2.26455523e-03,  -0.00000000e+00,\n",
       "        -0.00000000e+00,  -1.29630393e-02,  -4.25084601e-03,\n",
       "        -6.15960403e-03,   6.44348803e-03,  -0.00000000e+00,\n",
       "         1.70172583e-02,   1.00477675e-01,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,  -0.00000000e+00,\n",
       "         2.98772681e-02,   5.79231201e-02,   0.00000000e+00,\n",
       "         9.77996012e-03,   0.00000000e+00,   0.00000000e+00,\n",
       "         8.45501751e-03,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,  -0.00000000e+00,   3.98347210e-02,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -8.89504429e-03,\n",
       "         0.00000000e+00,   5.46594172e-03,  -0.00000000e+00,\n",
       "         2.00966347e-03,   0.00000000e+00,  -2.16657903e-02,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "        -0.00000000e+00,   3.02063900e-03,   0.00000000e+00,\n",
       "         0.00000000e+00,  -0.00000000e+00,  -0.00000000e+00,\n",
       "         5.99805014e-02,   0.00000000e+00,  -0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00])"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "print ('lasso.intercept_:',lasso.intercept_)\n",
    "lasso.coef_  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#在本任务中，最佳alpha为参数grid的最左端，最好再继续检查比当前更小的alpha是否会更好"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of Lasso Regression on test is 0.892648676657\n",
      "The value of default measurement of Lasso Regression on train is 0.923600945464\n"
     ]
    }
   ],
   "source": [
    "# 使用LinearRegression模型自带的评估模块（r2_score），并输出评估结果\n",
    "print 'The value of default measurement of Lasso Regression on test is', lasso.score(X_test, y_test)\n",
    "print 'The value of default measurement of Lasso Regression on train is', lasso.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Test = StandardScaler.transform(test_data)\n",
    "predict_value_lasso = lasso.predict(test_data)\n",
    "# final_predict_value_lasso = np.exp(predict_value_lasso)\n",
    "final_predict_value_lasso = ss_y.inverse_transform(predict_value_lasso)\n",
    "# ss['sale_price'] = predict_value_lasso\n",
    "# ss.head()\n",
    "# pred_lasso = pd.DataFrame(predict_value_lasso, index=test_data[\"Id\"], columns=[\"SalePrice\"])\n",
    "pred_lasso = pd.DataFrame(final_predict_value_lasso, columns=[\"SalePrice\"])\n",
    "pred_lasso.to_csv('Lasso_Predicting_house_price_output.csv', header=True, index_label='Id')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
